import { Http } from "@/utils/request";
import { Toast } from "@/utils/toast";
import { delayTask } from "@/utils/timer";

const baseUrl = "/pass_port_order";

export const comment_api = (data: any, showError = true) => {
  return Http.post(`/v1${baseUrl}/comment`, data).catch(error => {
    showError && delayTask(60, () => Toast.show(error.message));
    return Promise.reject(error);
  });
};

export const comment_info_api = (
  data: { relation_id: string },
  showError = true
) => {
  return Http.get<any>(`/v1${baseUrl}/comment_info`, data).catch(error => {
    showError && delayTask(60, () => Toast.show(error.message));
    return Promise.reject(error);
  });
};

export const order_set_api = (data: { specs_id: string }, showError = true) => {
  return Http.get<any>(`/v1${baseUrl}/order_set`, data).catch(error => {
    showError && delayTask(60, () => Toast.show(error.message));
    return Promise.reject(error);
  });
};

export const create_order_api = (data: any, showError = true) => {
  return Http.post<{ order_id: string }>(
    `/v1${baseUrl}/create_order`,
    data
  ).catch(error => {
    showError && delayTask(60, () => Toast.show(error.message));
    return Promise.reject(error);
  });
};

export const pay_api = (data: { order_id: string }, showError = true) => {
  return Http.post<any>(`/v1${baseUrl}/pay`, data).catch((error: Error) => {
    showError && delayTask(60, () => Toast.show(error.message));
    return Promise.reject(error);
  });
};
